<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <input type="file" id='file'>
  <button id='btn'>Click</button>
  <script src="https://cdn.bootcss.com/axios/0.19.2/axios.min.js"></script>
  <script>
    btn.onclick = function(){
      // console.log(file)
      var form = new FormData();
      // form.append('file', file.files[0]);
      var str = JSON.stringify({data: 'Upload'});
      var blob = new Blob([str], {type: 'text/plain'});
      form.append('file', blob, '1.txt');
      // FormData 上传的是blob
      var fileUploadUrl = 'http://localhost:8080';
      // var xhr = new XMLHttpRequest();
      // xhr.open('post', 'http://localhost:8080/', false);
      // xhr.send(form);
      // xhr.onload = function(){
      //   console.log(xhr.responseText);
      // }
      axios.post(fileUploadUrl, form).then(res => {
        console.log(res);
      })
    }
  </script>
</body>
</html>